package com.li.onjava8.concurrent.cf.example.cake;

import com.li.onjava8.concurrent.utils.Nap;

import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;

/**
 * 2.1 接下来，我们将单批面糊放入四个锅中进行烘烤。
 * @author li
 * @date 2023/10/31 15:07
 */

public class Baked {
    static class Pan {}

    static Pan pan(Batter b) {
        new Nap(0.1);
        return new Pan();
    }

    static Baked heat(Pan p) {
        new Nap(0.1);
        return new Baked();
    }

    static CompletableFuture<Baked> bake(CompletableFuture<Batter> cfb) {
        return cfb.thenApplyAsync(Baked::pan).thenApplyAsync(Baked::heat);
    }

    public static Stream<CompletableFuture<Baked>> batch(CompletableFuture<Batter> batter) {
        return Stream.of(bake(batter), bake(batter), bake(batter), bake(batter));
    }

}
